package service.local.beans;

import java.util.List;

import javax.ejb.DependsOn;
import javax.ejb.EJB;
import javax.ejb.Stateless;

import model.Comment;
import repository.CommentRepository;
import repository.exceptions.RepositoryException;
import service.ServiceException;
import service.local.CommentService;
@Stateless (name = "CommentService", mappedName = "CommentService")
@DependsOn ({"CommentRepository"})
public class CommentServiceBean implements CommentService {
	
	@EJB
	CommentRepository repo;
	@Override
	public Comment insertComment(Comment Comment){
		Comment r=new Comment();
		try {
			return repo.save (Comment);
		} catch (final RepositoryException ex) {
			//throw new ServiceException("Insert Comment failed", ex);
		}
		return r;
	}

	@Override
	public Comment updateComment(Comment Comment){
		try {
			repo.merge(Comment);
			return Comment;
		} catch (RepositoryException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}

	@Override
	public void deleteComment(Comment Comment) {
		try {
			repo.delete(Comment);
		} catch (RepositoryException e) {
			
		}
	}

	@Override
	public List<Comment> getAll(){
		try {
			return repo.getAll();
		}catch(final RepositoryException ex) {
			
		}
		return null;
	}
	
	



}
